package com.moli.iov.base.util;

import com.alibaba.fastjson.JSON;
import com.moli.iov.util.GsonUtil;


/**
 * @author whl
 */
public class BeanUtil {

    private static <T> String toFastjson(T entry){
        return JSON.toJSONString(entry);
    }

    private static <T> String toGson(T entry){
        return GsonUtil.toJsonWithSerializeNulls(entry);
    }

    private static <T> T parseGson(String str, Class<T> clazz) {
        return GsonUtil.parseJsonWithGson(str,clazz);
    }

    private static <T> T parseFastjson(String str, Class<T> clazz) {
        return JSON.parseObject(str,clazz);
    }


    public static <T> String toJson(T entry){
        return toFastjson(entry);
    }

    public static <T> T parse(String str, Class<T> clazz) {
        return parseFastjson(str,clazz);
    }

//    public static VehicleTbox parseGsonToVehicleTboxList(String json){
//        VehicleTbox tbox = new VehicleTbox();
//        tbox = JSON.parseObject(json,VehicleTbox.class);
//        return tbox;
//    }

//    public static List<VehicleTbox> parseFastJsonToVehicleTboxList(List<String> jsonList){
//        if(jsonList!=null && jsonList.size()>0){
//            List<VehicleTbox> list = new ArrayList<>();
//            VehicleTbox tbox = null;
//            for (String json : jsonList) {
//                tbox = JSON.parseObject(json, VehicleTbox.class);
//                list.add(tbox);
//            }
//            return list;
//        }
//        return null;
//    }



    /**
     * JSONObject jo = JSON.parseObject(json);
     *
     *                 Long id = jo.getLong("id");
     *                 Date registerTime = jo.getDate("registerTime");
     *                 Date bindTime = jo.getDate("bindTime");
     *                 String vin = jo.getString("vin");
     *                 String deviceModel = jo.getString("deviceModel");
     *                 String deviceId = jo.getString("deviceId");
     *                 String supplierName = jo.getString("supplierName");
     *                 String iccid = jo.getString("iccid");
     *                 String simNo = jo.getString("simNo");
     *
     *                 String bindRemark = jo.getString("bindRemark");
     *                 Integer bindingStatus = jo.getInteger("bindingStatus");
     *                 Date gmtCreate = jo.getDate("gmtCreate");
     *                 Date gmtModified = jo.getDate("gmtModified");
     *                 Integer isDelete = jo.getInteger("isDelete");
     *                 VehicleTbox tbox = new VehicleTbox();
     *                 tbox.setVin(vin);
     *                 tbox.setBindingStatus(bindingStatus);
     *                 tbox.setBindRemark(bindRemark);
     *                 tbox.setBindTime(bindTime);
     *                 tbox.setDeviceId(deviceId);
     *                 tbox.setDeviceModel(deviceModel);
     *                 tbox.setGmtCreate(gmtCreate);
     *                 tbox.setGmtModified(gmtModified);
     *                 tbox.setIccid(iccid);
     *                 tbox.setId(id);
     *                 tbox.setIsDelete(isDelete);
     *                 tbox.setRegisterTime(registerTime);
     *                 tbox.setSupplierName(supplierName);
     *                 tbox.setSimNo(simNo);
     */
}
